<?php
require_once '../sub/init.php';
if(!is_mobile())header("Location: ".Href('money'));
$currfields = 'sex,grade,openid,subscribe,money';
require_once ZEAI.'m/my_chk_u.php';
require_once ZEAI.'cache/config_vip.php';
if($_VIP['ifmoney'] == 0){exit('余额账户已关闭');}
require_once ZEAI.'cache/config_wxgzh.php';
$t = (ifint($t,'1-4','1'))?$t:1;
$cook_grade = intval($row['grade']);
$cook_sex   = intval($row['sex']);
$cook_money = $row['money'];
$cook_openid= $row['openid'];
$cook_subscribe = $row['subscribe'];

if($submitok == 'ajax_tx_update'){
	if(empty($_VIP['rmb_txlist']))json_exit(array('flag'=>0,'msg'=>'提现已关闭'));
	if(!ifint($tx_money,"0-9","1,9"))json_exit(array('flag'=>0,'msg'=>'提现的金额必须是正整数'));
	$tx_money = abs(intval($tx_money));
	if($tx_money > $cook_money)json_exit(array('flag'=>0,'msg'=>'账户余额不足'.$tx_money));
	$endnum  = $cook_money-$tx_money;
	$orderid = "TX_".$cook_uid."_".$tx_money."_".date("Ymdhis");
	$db->query("UPDATE ".__TBL_USER__." SET money=".$endnum." WHERE money>=".$tx_money." AND id=".$cook_uid);
	//写清单
	$title   = "申请提现(手机)";
	$content = "申请提现<span class=\"Cf60 S12\">（等待处理）</span>";
	$money_list_id = $db->AddLovebRmbList($cook_uid,$content,-$tx_money,'money',2);
	$paymoney = intval($_VIP['rmb_tx_zknum']*$tx_money);
	//生成提现记录
	$db->query("INSERT INTO ".__TBL_PAY__." (uid,orderid,money_list_id,kind,title,money,paymoney,addtime) VALUES ($cook_uid,'$orderid',$money_list_id,-1,'$title','$tx_money','$paymoney',".ADDTIME.")");
	//站内消息
	$C = $cook_nickname.'您好，您的余额账户资金有变动！　<a href='.a('{"kind":"money","mp":"pc"}').' class=aQING>查看详情</a>';
	$db->SendTip($cook_uid,'余额提现',dataIO($C,'in'),'sys');
	//账户资金变动提醒
	if (!empty($cook_openid) && $cook_subscribe==1){
		$first  = urlencode($cook_nickname."您好，您的余额账户资金有变动：");
		$remark = urlencode("申请提现扣除");
		@wx_mb_sent('mbbh=ZEAI_ACCOUNT_CHANGE&openid='.$cook_openid.'&num=-'.$tx_money.'&endnum='.$endnum.'&first='.$first.'&remark='.$remark.'&url='.urlencode(a('{"kind":"money","mp":"mob"}')));
	}
	//
	json_exit(array('flag'=>1,'msg'=>'提现申请已提交，请等待处理'));
}


if($t == 2){
	function rows_ulist($rows,$p) {
		global $_ZEAI;
		$id       = $rows['id'];
		$content  = dataIO($rows['content'],'out');
		$num      = $rows['num'];
		$addtime  = YmdHis($rows['addtime']);
		if ($num<0){$numstyle = "fs";}else{$numstyle = "zs";$num = '+'.$num;}
		$O = '<dl><dt>'.$content.'<font>'.$addtime.'</font></dt><dd class="'.$numstyle.'">'.$num.'</dd></dl>';
		return $O;
	}
	$nodatatips="<div class='nodatatips'><i class='ico' style='font-size:60px'>&#xe608;</i>暂时木有内容</div>";
	$_ZEAI['pagesize'] = 15;
	$ZEAI_SQL = "uid=".$cook_uid;
	$ZEAI_SELECT="SELECT id,content,num,addtime FROM ".__TBL_MONEY_LIST__." WHERE  ".$ZEAI_SQL." ORDER BY id DESC";
	if($submitok=='ZEAI_list'){exit(Zeai_ajax_list_fn($ZEAI_totalP,$p));}
	$ZEAI_total = $db->COUNT(__TBL_MONEY_LIST__,$ZEAI_SQL);
	$ZEAI_totalP= ceil($ZEAI_total/$_ZEAI['pagesize']);
}
$nav='my';?>
<!doctype html><html><head><meta charset="utf-8">
<title>我的-<?php echo $_ZEAI['siteName'];?></title>
<?php echo HEADMETA; ?>
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo RES;?>m/css/my_loveb_money.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo HOST;?>/cache/zeaicolor.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<style>
.my_loveb_ye{padding-top:<?php echo ($signflag == 0)?'8':'';?>8px}
.my_loveb_ye .LoveB:before{content:'当前人民币';}
.my_loveb_ye .LoveB{color:<?php echo $_ZEAI['mob_mbcolor'];?>;}
.my_loveb_ye .box .dt i{color:<?php echo $_ZEAI['mob_mbcolor'];?>}
.my_loveb_cz .nextbtn{box-shadow:0 3px 8px rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.4)} 
.tabmenu a.ed:after{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
header.bgcolor{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
#backtop a,.btmKefuBtn{background-color:<?php echo $_ZEAI['mob_mbcolor'];?>}
.nextbtn{box-shadow:0 .3rem .8rem rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.4);background-color:#fff;background:-webkit-linear-gradient(315deg,rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.6) 0%,<?php echo $_ZEAI['mob_mbcolor'];?> 100%)}
<?php
if ($_ZEAI['m_mb']==2){
	echo '.TRnav_btn i{color:'.$_ZEAI['mob_mbcolor'].'}';
	echo '.tabmenufix{width:60%;max-width:500px;top:1.5rem;margin:auto;left:0;right:0}';
	
	$padding_top = ($signflag == 0)?'5rem':'.8rem';
	echo '.my_loveb_ye{padding-top:'.$padding_top.'}';
	echo '.my_loveb_mx{padding-top:5rem}';
	echo '.my_loveb_cz{padding-top:9rem}';

	$mini_class='top_mini4';
}else{
	$padding_top = ($signflag == 0)?'8.8rem':'.8rem';
	echo '.my_loveb_ye{padding-top:'.$padding_top.'}';
	$mini_class='top_mini4 zeaibg bgcolor yunbox';
}
?>
</style>
</head>
<body>
<?php
$mini_href ='zeai.openurl(\'my.php\');';
$mini_title='我的余额账户';
require_once ZEAI.'m/top_mini.php';
$mm=2;
if(str_len($_VIP['rmb_czlist'])>2)$mm++;
if(str_len($_VIP['rmb_txlist'])>2)$mm++;
?>
<div class="tabmenu tabmenu<?php echo $mm;?> tabmenufix">
	<a href="my_money.php?t=1"<?php echo ($t == 1)?' class="ed"':'';?>>余额</a>
	<a href="my_money.php?t=2"<?php echo ($t == 2)?' class="ed"':'';?>>明细</a>
	<?php if(!empty($_VIP['rmb_czlist'])){?><a href="my_money.php?t=3"<?php echo ($t == 3)?' class="ed"':'';?>>充值</a><?php }?>
    <?php if(!empty($_VIP['rmb_txlist'])){ ?><a href="my_money.php?t=4"<?php echo ($t == 4)?' class="ed"':'';?>>提现</a><?php }?>
</div>
<!--*********余额*********-->
<?php switch ($t){case 1:?>
    <div class="my_loveb_ye">
        <div class="box">
            <div class="dt"><i class="ico">&#xe61a;</i></div>
            <div class="dd"><span class="LoveB" id="LoveB"><?php echo str_replace(".00","",number_format($cook_money,2));?><font>元</font></span></div>
        </div>
        <div class="clear"></div>
        <div class="loveBdetail">
            <?php if(@in_array('hb',$navarr)){?>● 余额可用来发红包<br><?php }?>
            ● 兑换<?php echo $_ZEAI['loveB'];?>　　<a class="zeaicolor" href="my_loveb.php?t=3"><i class="ico">&#xe618;</i> 我要兑换</a><br>
            <?php if(str_len($_VIP['rmb_txlist'])>2){ ?>● 可以提现至您的微信钱包<?php }?><br><br><br>
            <a href="c.php?submitok=my_money_getTip" class="btn yuan size4 nextbtn">如何获得余额？</a>
        </div>
    </div>
<!--*********明细*********-->
<?php break;case 2:?>
    <div class="my_loveb_mx" id="ZEAI_list"><?php if($ZEAI_totalP>0){echo Zeai_ajax_list_fn($ZEAI_totalP,$p);}else{echo $nodatatips;}?></div>
    <script>
    <?php
    if ($ZEAI_total > $_ZEAI['pagesize']){?>
    var ZEAI_totalP = parseInt(<?php echo $ZEAI_totalP; ?>),p=2;
    zeaiOnscroll_json={url:'my_loveb'+zeai.extname,data:{submitok:'ZEAI_list',ZEAI_totalP:ZEAI_totalP,t:2}};
    document.body.onscroll = zeaiOnscroll;
    <?php }?>
    </script>
	<div id="backtop"><a href="#top" id="btmTopBtn"><i class="ico">&#xe60a;</i>顶部</a></div>
<!--*********充值*********-->
<?php break;case 3:
	if($_VIP['rmb_czlist']=='0')exit('<div class="nodatatips">充值已关闭</div>');
	?>
	<style>.my_loveb_cz dl dd em.ed{background-color:rgba(<?php echo c16_rgb($_ZEAI['mob_mbcolor']);?>,.1);color:<?php echo $_ZEAI['mob_mbcolor'];?>}</style>
    <form id="zeaiFORM" class="my_loveb_cz my_rmb_ye">
    <dl>
        <dt>充值数量</dt>
        <dd id="numlist">
        	<?php
			$ARR = json_decode($_VIP['rmb_czlist'],true);;
			if (@count($ARR) >= 1 && is_array($ARR)){
				foreach ($ARR as $k=>$bV) {
					$cls=($k==0)?' class="ed"':'';
					$V=round($bV,2);
					echo '<em rmb="'.$V.'"'.$cls.'>'.$bV.'元</em>';
				}
			}
			?>
        </dd>
    </dl>
    <dl class="rmbdl"><dt>应付金额</dt><dd><span id="price"></span><span id="pricetitle"></span></dd></dl>
    <div style="text-align:center;margin:20px auto"><button type="button" class="btn size4 nextbtn zeaibg" id="nextbtn">下一步</button></div>
    <?php
		$jump_url = (!empty($jumpurl))?urldecode($jumpurl):a('{"kind":"money","mp":"mob"}');
		$money = 0;
		$kind  = 3;
		echo '<input type="hidden" id="money" value="'.$money.'">';
	?>
    </form>
	<script>
	var loveBzk = 1;
	var czlist  = numlist.getElementsByTagName("em");
    zeai.listEach(czlist,function(obj){
		if (obj.hasClass('ed')){priceInit(obj);}
		obj.onclick=function(){priceInit(obj);cleardom(obj);}
	});
	function priceInit(obj){
		var rmb=obj.getAttribute("rmb");
		var endrmb=rmb*loveBzk;
		//endrmb=endrmb.toFixed(2);
		endrmb=returnFloat(endrmb);
		o('money').value = endrmb;
		price.html(endrmb+'元');
		var tt = '';
		if(loveBzk < 1)tt=' （'+loveBzk*10+'折优惠<s>原价'+rmb+'元</s>）';
		pricetitle.html(tt);
	}
	function cleardom(curdom){
		zeai.listEach(czlist,function(obj){obj.removeClass('ed');});
		curdom.addClass('ed');
	}
	nextbtn.onclick=function(){
		if (o('money').value<=0){zeai.msg('请选择');return false;}
		money=o('money').value;o('money_str').html(money+'元');
		ZeaiM.div_up({obj:czbox,h:<?php echo (is_weixin())?23.5:30.5;?>});
	}
	function returnFloat(value){
		var value=Math.round(parseFloat(value)*100)/100;
		var xsd=value.toString().split(".");
		if(xsd.length==1){
			value=value.toString()+".00";
			return value;
		}
		if(xsd.length>1){
			if(xsd[1].length<2){
				value=value.toString()+"0";
			}
			return value;
		}
	}
    </script><?php
	require_once 'my_pay.php';?>
<!--*********提现*********-->
<?php break;case 4:if(empty($_VIP['rmb_txlist']))exit('<div class="nodatatips">提现已关闭</div>');?>
	<style>
	.tg_my_money_tx{padding:1rem 0;margin-bottom:4rem;margin-top:<?php echo ($_ZEAI['m_mb']==2)?6:10;?>rem}
	.tg_my_money_tx form{width:90%;margin:2rem auto}
	.tg_my_money_tx h4{margin:2.5rem 0 1rem 0}
	.tg_my_money_tx li{text-align:left;width:29%;padding:1rem 2rem 1rem 1rem;margin:1rem 2%;float:left;border:#eee 1px solid;border-radius:4rem;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}
	/*.tg_my_money_tx li .radioskin-label b{margin:0 0 0 .2rem}*/
	.tg_my_money_tx h5{color:#666;padding:2rem 0 .5rem 0}
	.tg_my_money_tx h6{color:#999;margin:1rem auto;text-align:left;width:85%;}
    </style>
	<div class="tg_my_money_tx">
		<!--<h4>请选择提现金额<br><span class="S14 C999">当前余额：<font class="Cf00">￥<?php echo str_replace(".00","",number_format($cook_money,2));?>元</font></span></h4>-->
        <form id="z_e_a_i__c_n__tx_form"><?php
			$ARR = json_decode($_VIP['rmb_txlist'],true);
			if (@count($ARR) >= 1 && is_array($ARR)){
				$n=1;
				foreach ($ARR as $k=>$bV) {
					$cls=($k==0)?' checked':'';
					$V=intval($bV);?>
                    <li><input type="radio" name="tx_money" id="tx_money<?php echo $n;?>" class="radioskin" value="<?php echo $V;?>"<?php echo $cls;?>><label for="tx_money<?php echo $n;?>" class="radioskin-label"><i class="i1"></i><b class="W80 S14"><?php echo $V;?>元</b></label></li>
                    <?php
					$n++;
				}
			}?>
        	<input type="hidden" name="submitok" value="ajax_tx_update">
        </form>
        <div class="clear"></div>
       <?php if ($_VIP['rmb_tx_zknum'] < 1){ ?>
       <h5>提现将收取<?php echo (1-$_VIP['rmb_tx_zknum'])*100; ?>%的手续费</h5>
       <?php }?>
       <div style="text-align:center;margin:2rem auto"><button type="button" class="btn size4 zeaibg yuan W85_ nextbtn" id="txbtn">立即提现</button></div>
       <?php if ($_VIP['rmb_tx_zknum'] < 1){ ?>
        <div class="linebox">
            <div class="line W50"></div>
            <div class="title BAI S14">温馨提醒</div>
        </div>
        <h6 class="lineH200 S14">为了补贴网站运营和服务器成本，我们将扣除部分手续费，实际到账<?php echo $_VIP['rmb_tx_zknum']*100; ?>％，有小数的将取整处理</h6>
        <?php }?>
		<script>
        txbtn.onclick = function(){
            zeai.confirm('您真要提现么？',function (){zeai.ajax({url:'my_money'+zeai.extname,js:1,form:z_e_a_i__c_n__tx_form},function(e){var rs=zeai.jsoneval(e);
				if (rs.flag==1){
					zeai.msg(rs.msg);
					setTimeout(function(){zeai.openurl('my_money.php');},1000);
				}else{
					zeai.msg(rs.msg);
				}
			});});
        }
		<?php
		if (!empty($_GZH['wx_gzh_ewm']) && ($cook_subscribe!=1)){
			@wx_endurl('您刚刚浏览的页面【余额提现】',HOST.'/m/my_money.php?t=4');?>
			setTimeout(function(){ZeaiM.div({obj:o('subscribe_box_my_money_tx'),w:26,h:28});},500);
			<?php
		}?>
        </script>
        <div id="subscribe_box_my_money_tx" class="my-subscribe_box"><img src="<?php echo UP.$_GZH['wx_gzh_ewm']; ?>">
            <h3>
            <?php if (!is_weixin()){?>请用微信打开使用提现功能<br><?php }?>
            长按或微信扫码关注公众号<br>
            <?php if (is_weixin()){?>关注成功才能打款给您的微信零钱<?php }?>
            </h3>
        </div>
    </div>

	
	<?php
break;}
if($_ZEAI['m_mb']==2){
	require_once ZEAI.'m/bottom2.php';
}else{
	require_once ZEAI.'m/TRnav.php';
	require_once ZEAI.'m/bottom.php';
}
?>